package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.domain.UserBaseGroup;
import com.ruoyi.system.domain.UserVisualBase;
import com.ruoyi.system.service.UserBaseGroupService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @Author tang ao long
 * @Date 2020-08-30 22:08
 * @Version 1.0
 */
@Controller
@RequestMapping("/system/UserBaseGroup")
public class SysUserBaseGroupController extends BaseController {

    @Autowired
    private UserBaseGroupService userBaseGroupService;

    private String prefix = "system/userbasegroup";

    @RequiresPermissions("system:userBaseGroup:view")
    @GetMapping()
    public String userBaseGroup()
    {
        return prefix + "/userBaseGroup";
    }

    /**
     * 查询用户大屏分组信息
     * @param userBaseGroup 查询对象
     * @return 返回查询结果
     */
    @RequiresPermissions("system:userBaseGroup:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserBaseGroup userBaseGroup)
    {
        startPage();
        List<UserBaseGroup> userBaseGroupList = userBaseGroupService.selectUserBaseGroupByInfo(userBaseGroup);
        return getDataTable(userBaseGroupList);
    }

    /**
     * 删除大屏分组信息
     * @param ids 待删除的ID列
     * @return 返回删除结果
     */
    @RequiresPermissions("system:userBaseGroup:remove")
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userBaseGroupService.deleteUserBaseGroupByIds(ids));
    }

    /**
     * 修改大屏分组信息
     */
    @RequiresPermissions("system:userBaseGroup:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map)
    {
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        map.put("user",user);
        map.put("userBaseGroup", userBaseGroupService.selectUserBaseGroupInfoById(id));
        return prefix + "/edit";
    }

    /**
     * 大屏信息更新
     */
    @RequiresPermissions("system:userVisualBase:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@Validated UserBaseGroup userBaseGroup)
    {
        userBaseGroup.setUpdateId(ShiroUtils.getSysUser().getUserId().toString());
        userBaseGroup.setUpdateName(ShiroUtils.getSysUser().getLoginName());
        return toAjax(userBaseGroupService.updateUserBaseGroupById(userBaseGroup));
    }

    /**
     * 检查大屏名称是否重复
     */
    @PostMapping("/checkUserBaseGroupUnique")
    @ResponseBody
    public Boolean checkUserBaseGroupUnique(@Validated String id,@Validated String groupName){
        return userBaseGroupService.checkUserBaseGroupUnique(groupName,id) <= 0;
    }

}
